#!/usr/bin/env python
# -*- coding: UTF-8 -*-

# Magpie - an open source discussion forum system.
#
# Copyright (C) 2009 The Magpie Team
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.

import pytz

from ajiaojr import magpie
from ajiaojr.commons.appengine.django.forms import KeyNameInputField
from ajiaojr.magpie import models

from django import forms

from google.appengine.ext.db import djangoforms

class ClubConfigForm(djangoforms.ModelForm):
  is_enabled = forms.BooleanField(required=False)
  is_read_only = forms.BooleanField(required=False)
  is_pm_enabled = forms.BooleanField(required=False)
  is_pm_read_only = forms.BooleanField(required=False)
  is_bank_enabled = forms.BooleanField(required=False)
  
  class Meta:
    model = models.ClubConfig
    
class ClubUserForm(djangoforms.ModelForm):
  signature = forms.CharField(widget=forms.Textarea(attrs={
                                                           'rows': 20,
                                                           'cols': 70,
                                                           }),
                                                           required=False)
  time_zone = forms.ChoiceField(choices=magpie.SUPPORTED_TIMEZONES)
  class Meta:
    model = models.ClubUser
    exclude = [
               'user',
               'user_group',
               'is_enabled',
               'mine_dropped'
               ]
    
class ForumCategoryForm(djangoforms.ModelForm):
  is_public = forms.BooleanField(required=False)
  group_can_read = forms.BooleanField(required=False)
  group_can_write = forms.BooleanField(required=False)
  other_can_read = forms.BooleanField(required=False)
  other_can_write = forms.BooleanField(required=False)
  
  class Meta:
    model = models.ForumCategory
    exclude = [
               'is_deleted',
               'forums',
               ]

class ForumForm(djangoforms.ModelForm):
  is_public = forms.BooleanField(required=False)
  group_can_read = forms.BooleanField(required=False)
  group_can_write = forms.BooleanField(required=False)
  other_can_read = forms.BooleanField(required=False)
  other_can_write = forms.BooleanField(required=False)
  
  class Meta:
    model = models.Forum
    exclude = [
               'is_deleted',
               ]

class ForumPostForm(djangoforms.ModelForm):
  title = forms.CharField(widget=forms.TextInput(attrs={
                                                        'size': 70,
                                                        }))
  contents = forms.CharField(widget=forms.Textarea(attrs={
                                                          'rows': 20,
                                                          'cols': 70,
                                                          }))
  class Meta:
    model = models.ForumPost
    exclude = [
               'is_deleted',
               'is_marked',
               'is_pinned',
               'is_locked',
               'is_recommended',
               'post_index',
               'replies',
               'last_reply_index',
               'author_ip',
               ]
    
class MineGoldConfigForm(djangoforms.ModelForm):
  is_enabled = forms.BooleanField(required = False)
  
  class Meta:
    model = models.MineGoldConfig
    
class PrivateMessageForm(djangoforms.ModelForm):
  sender = KeyNameInputField(models.ClubUser, widget=forms.HiddenInput())
  recipient = KeyNameInputField(models.ClubUser, widget=forms.TextInput(attrs={
                                                        'size': 70,
                                                        }))
  title = forms.CharField(widget=forms.TextInput(attrs={
                                                        'size': 70,
                                                        }))
  contents = forms.CharField(widget=forms.Textarea(attrs={
                                                          'rows': 20,
                                                          'cols': 70,
                                                          }))
  class Meta:
    model = models.PrivateMessage
    exclude = [
               'is_deleted',
               'is_read',
               'message_time',
               'message_index',
               ]

class UserGroupForm(djangoforms.ModelForm):
  class Meta:
    model = models.UserGroup
    
class UserInGroupForm(djangoforms.ModelForm):
  club_user = KeyNameInputField(models.ClubUser,
                                widget = forms.TextInput())
  class Meta:
    model = models.UserInGroup
    exclude = [
               'user_group',
               ]
